package com.lzj.gen;

import cn.hutool.core.io.FileUtil;
import com.lzj.gen.jetbrains.CertUtil;
import com.lzj.gen.jetbrains.CodeUtil;
import com.lzj.gen.jetbrains.LicenseUtil;
import com.lzj.gen.jetbrains.PowerConfigUtil;

import java.nio.charset.Charset;

/**
 * Created by lzj on 2023/11/24
 * https://bafybeih65no5dklpqfe346wyeiak6wzemv5d7z2ya7nssdgwdz4xrmdu6i.ipfs.dweb.link
 */
public class FuckJB {

    public static void main(String[] args) throws Exception {
        String baseDir = "D:/CodeWorkspace/JavaWorkspace/power-config/src/main/resources/jetbra";
        String certFile = baseDir + "/cert/ca.crt";
        String keyFile = baseDir + "/cert/ca.key";
        String powerConfigDir = baseDir + "/config-jetbrains";
        String activeCodeFile = baseDir + "/active-code.txt";
        //生成证书及power.conf配置文件，只需要生成一次即可，后续不需要再生成
        genCertAndConfig(certFile, keyFile, powerConfigDir);

        //生成全家桶授权证书
        String license = LicenseUtil.genLicenseForAll("敖癸", "2099-09-09");
        //生成激码
        String activeCode = CodeUtil.genActiveCode(certFile, keyFile, license);
        FileUtil.writeString(activeCode, activeCodeFile, Charset.defaultCharset());
    }

    /**
     * 生成证书及power.conf配置
     * @param certFile
     * @param keyFile
     * @param powerConfigBase
     * @throws Exception
     */
    private static void genCertAndConfig(String certFile, String keyFile, String powerConfigBase) throws Exception {
        CertUtil.genCert(certFile, keyFile);
        PowerConfigUtil.genPowerPluginConfig(certFile, powerConfigBase);
    }

}
